<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>新增种子·思通投研·让数据驱动投资价值!</title>

<link href="${pageContext.request.contextPath }/img/webLogoIcon.png"
	rel="shortcut icon">
<link href="${pageContext.request.contextPath }/css/bootstrap.min.css"
	rel="stylesheet">
<link href="${pageContext.request.contextPath }/css/font-awesome.css"
	rel="stylesheet">
<link href="${pageContext.request.contextPath }/css/custom.css"
	rel="stylesheet">
<link href="${pageContext.request.contextPath }/css/animate.css"
	rel="stylesheet">
<link href="${pageContext.request.contextPath }/css/style.css"
	rel="stylesheet">
<link href="${pageContext.request.contextPath }/css/datatables.min.css"
	rel="stylesheet">
<link href="${pageContext.request.contextPath }/css/toastr.min.css"
	rel="stylesheet" />
<link
	href="${pageContext.request.contextPath }/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css"
	rel="stylesheet">
<link
	href="${pageContext.request.contextPath }/css/plugins/sweetalert/sweetalert.css"
	rel="stylesheet">
<link
	href="${pageContext.request.contextPath }/css/jquery.searchableSelect.css"
	rel="stylesheet" type="text/css">
<link
	href="${pageContext.request.contextPath }/css/plugins/iCheck/custom.css"
	rel="stylesheet">
	<link href="${pageContext.request.contextPath}/css/mypage.css" rel="stylesheet">
	<link href="${pageContext.request.contextPath}/css/sweetalert2.min.css" rel="stylesheet">
<style>
.select2_demo_1 {
	float: left;
	width: 120px;
	display: inline;
	margin-left: 10px;
}

.form-control {
	display: inline;
}

.col-sm-3 {
	float: right;
	width: 560px;
}

.input-group {
	float: right;
	width: 240px;
	margin-left: 5px;
}

.checkbox {
	padding-left: 35px;
	float: left;
}

.leadset {
	width: 100%;
	overflow: hidden;
	clear: both;
}

.leadset button {
	float: right;
}

.tablebox {
	margin-top: 15px;
}
</style>
</head>

<body>

	<div id="wrapper">

		<nav class="navbar-default navbar-static-side" role="navigation">
		<%request.setAttribute("LEFT", "websitelist");%> <%@include
			file="left-factory.jsp"%> </nav>

		<div id="page-wrapper" class="gray-bg">
			<div class="row border-bottom">
				<jsp:include page="head-factory.jsp" flush="true" />
			</div>
			<div class="row wrapper border-bottom white-bg page-heading">
				<div class="col-lg-10">
					<h2>爬虫列表</h2>
				</div>
			</div>
			<div class="wrapper wrapper-content">
				<div class="ibox-content">
					<span style="font-size: 17px;" id="websiteId"
						data-id="${websiteId }">网站名称:${websitename } </span>
					<button class="btn btn-white pull-right"
						onclick="javascrtpt:window.location.href='${pageContext.request.contextPath }/listseed?websiteId=${websiteId}'"
						type="button">返回</button>
					<div class="hr-line-dashed"></div>
					<div class="table-responsive">
						<div class="panel-body">
<!-- 								<button class="btn btn-primary" onclick="addseed()">导入配置</button> -->
								
							<div class="leadset">
								<select id="selectType" onchange="JumpToPage(1)">
									<option value="0" ${type == 0 ? 'selected':'' }>全部</option>
									<option value="1" ${type == 1 ? 'selected':'' }>匹配成功</option>
									<option value="2" ${type == 2 ? 'selected':'' }>匹配失败</option>
								</select>
								<button id="leadSet" class="btn btn-primary" onclick="addseed()">导入配置</button>
								<button id="addurl" class="btn btn-primary" onclick="addurl()">添加URL</button>
							</div>
							<div class="tablebox">
								<div class="table-responsive">
									<table class="table table-striped table-bordered table-hover">
										<thead>
											<tr>
												<th style="width: 40px;"></th>
												<th>URL</th>
												<th>类型</th>
												<th>配置项</th>
											</tr>
										</thead>
										<tbody>
											<c:forEach var="MappingSpider" items="${list.list }">
												<tr>
													<td><input id="MappingSpiderId" type="checkbox" ${MappingSpider.configUtilId != null ? 'checked ':'' } class="i-checks"
														name="input[]" value="${MappingSpider.id }"></td>
													<td><a href="${MappingSpider.url }" target="_black">${MappingSpider.url }</a></td>
													<td><input id="${MappingSpider.id}" style="font-size:20px;" size="55"  value="${MappingSpider.url_name }"></input><button class="btn btn-primary" style="float:right" onclick="updatename(${MappingSpider.id})">确定</button></td>
													<td>
														<c:if test="${MappingSpider.configUtilId != null}">
															<select id="change${MappingSpider.id }" onchange="change(${MappingSpider.id })">
																<option value="0">${MappingSpider.seed_util_name }</option>
																<c:forEach var="config" items="${seed_config_utils}">
																	<option value="${config.id }">${config.seed_util_name }</option>
																</c:forEach>
															</select>
															<!-- <button class="btn btn-primary" onclick="">${MappingSpider.seed_util_name }</button>   -->
														</c:if>
														<c:if test="${MappingSpider.configUtilId == null}">
															<select id="change${MappingSpider.id }"  onchange="change(${MappingSpider.id })">
																<option value="0">添加策略</option>
																<c:forEach var="config" items="${seed_config_utils}">
																<option value="${config.id}">${config.seed_util_name }</option>
																</c:forEach>
															</select>
														<!-- 
															<button class="btn btn-primary" onclick="">+添加配置</button>
														 -->
														</c:if>
													</td>
												</tr>
											</c:forEach>
										</tbody>
										<tfoot>
											<tr>
												<td colspan="7"><c:if test="${list.pages>0}">
														<div class="box" id="box" style="float: right;"></div>
													</c:if></td>
											</tr>
										</tfoot>
									</table>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			<jsp:include page="footer.jsp" flush="true" />
		</div>
	</div>



	<!-- Mainly scripts -->
	<script src="${pageContext.request.contextPath }/js/jquery-2.1.1.js"></script>
	<script src="${pageContext.request.contextPath }/js/bootstrap.min.js"></script>
	<script
		src="${pageContext.request.contextPath }/js/jquery.metisMenu.js"></script>
	<script
		src="${pageContext.request.contextPath }/js/jquery.slimscroll.min.js"></script>
	<script
		src="${pageContext.request.contextPath }/js/jquery.jeditable.js"></script>
	<script src="${pageContext.request.contextPath }/js/datatables.min.js"></script>

	<!-- Peity -->
	<script
		src="${pageContext.request.contextPath }/js/jquery.peity.min.js"></script>

	<!-- Custom and plugin javascript -->
	<script src="${pageContext.request.contextPath }/js/inspinia.js"></script>
	<script src="${pageContext.request.contextPath }/js/pace.min.js"></script>

	<!-- Peity -->
	<script src="${pageContext.request.contextPath }/js/peity-demo.js"></script>

	<!-- toastr -->
	<script
		src="${pageContext.request.contextPath }/js/plugins/toastr/toastr.min.js"></script>
	<!-- Sweet alert -->
	<script
		src="${pageContext.request.contextPath }/js/plugins/sweetalert/sweetalert.min.js"></script>

	<script
		src="${pageContext.request.contextPath }/js/jquery.searchableSelect.js"></script>
	<!-- Page-Level Scripts -->
	<script
		src="${pageContext.request.contextPath }/js/plugins/iCheck/icheck.min.js"></script>
    <!-- FooTable -->
    <script src="${pageContext.request.contextPath }/js/footable.all.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/mypage.js"></script>
    <script src="${pageContext.request.contextPath}/js/sweetalert2.all.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/jquery.blockUI.js"></script>
	<script>
        $(document).ready(function(){
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
        });
        $(document).ready(function() {

            $('.footable').footable();

        });
        $(function(){
			paging(1,'${list.pages }','${list.pageNum }');
		});
		function paging(totalData,totalPage, pagenum) {
			$('#box').paging({
				initPageNo : pagenum, // 初始页码
				totalPages : totalPage, //总页数
				totalCount : '合计' + totalData + '条数据', // 条目总数
				slideSpeed : 600, // 缓动速度 单位毫秒
				jump : true, //是否支持跳转
				callback : function(page) {
					// 回调函数
				}
			});
		}

		function JumpToPage(pagenum) {
			var type = $("#selectType").val()
			console.log(type);	
			window.location.href = "${pageContext.request.contextPath}/website_splist?websiteId=${websiteId}&website_name=${websitename}&pageNum=" +pagenum+"&type="+type;
			
		}
		
		//名称修改
		function updatename(mappingId){
			var urlname = $("#"+mappingId).val()
			console.log(mappingId);	
			console.log(urlname);
			$.ajax({
				url : "${pageContext.request.contextPath}/change/urlname",
        		type : "post",
        		data:{
        			urlname: urlname,
        			MappingSpiderId: mappingId
        		},
		    	success:function(res){
		    		if(res!=500){
		    			//showtips("修改成功！")
		    			alert("名称修改成功！")
		    		}
		    	},
		    	error:function(e){
		    		
		    	}
		    })
		}
		
		//策略修改
		function change(mappingId) {
			var configId  = $("#change"+mappingId).val()
			//var MappingSpiderId = $("#MappingSpiderId").val()
			console.log(configId);	
			console.log(mappingId);	
			$.ajax({
				url : "${pageContext.request.contextPath}/change/method",
        		type : "post",
        		data:{
        			configId: configId,
        			MappingSpiderId: mappingId
        		},
		    	success:function(res){
		    		if(res!=500){
		    			//showtips("修改成功！")
		    			alert("策略匹配修改成功！")
		    		}
		    	},
		    	error:function(e){
		    		
		    	}
		    })
		}
		
		//url添加
		function addurl(){
			window.location.href = "${pageContext.request.contextPath}/addurl/urlname?websiteId=${websiteId}&websitename=${websitename}";     
		}
    </script>
<script>
//跑马灯方法 

function addseed(){
    obj = document.getElementsByName("input[]");
    check_val = [];
    for(k in obj){
        if(obj[k].checked)
            check_val.push(obj[k].value);
    }
console.log(check_val); 
var ids ='';
if(check_val.length < 1 ){
	toastr.error('请勾选配置')
	return;
}
for(var i=0;i<check_val.length;i++){
	if(i == check_val.length-1){
		ids += check_val[i];
	}else{
		ids += check_val[i]+","
	}
}
	console.log(ids)
    //导入方法
    $.ajax({
    	url:"${pageContext.request.contextPath}/websitetactics/addseeds",
    	type:"post",
    	scriptCharset: 'GBK',
    	data:ids,
    	//数据加载前 加载动画
		beforeSend : function() {
			$("#leadSet").attr("disabled",true);
			$("#leadSet").text("正在导入...");
		},
		//数据加载完成后清除动画
		complete : function() {
// 			$("#leadSet").removeAttr("disabled");
			$("#leadSet").text("导入配置");
		},
    	success:function(res){
    		console.log(res)
    		if(res.status == 200){
    			$("#leadSet").removeAttr("disabled");
    			$("#leadSet").text("导入配置");
    			toastr.success(res.msg);
//     			setTimeout(() => {
//     				JumpToPage(1);
// 				}, 2000);
    		}
    	},
    	error:function(e){
    		
    	}
    })
}
// 	 function init(){
// 		    //获取标题
// 		    var title=document.title;
// 		    //分割字符串--->字符数组
// 		    var arr=title.split("");
// 		    //删除第一个元素并返回该元素
// 		    var e=arr.shift();
// 		    //把一个对象添加到数组末尾
// 		    arr.push(e);
// 		    //把数组转换成字符串
// 		    var marquee=arr.join("");
// 		    //返回给浏览器
// 		    document.title=marquee;
// 		    //定时一直执行
// 		    window.setTimeout("init()",1000);
// 		}
// 		window.onload=init;
	 
    </script>

</body>

</html>
